var cityList = [
{"name":"广州市","region":"440100"},    
{"name":"深圳市","region":"440300"}, 
{"name":"珠海市","region":"440400"},
{"name":"汕头市","region":"440500"},
{"name":"佛山市","region":"440600"},
{"name":"韶关市","region":"440200"},
{"name":"河源市","region":"441600"},
{"name":"梅州市","region":"441400"},
{"name":"惠州市","region":"441300"},
{"name":"汕尾市","region":"441500"},
{"name":"东莞市","region":"441900"},
{"name":"中山市","region":"442000"},
{"name":"江门市","region":"440700"},
{"name":"阳江市","region":"441700"},
{"name":"湛江市","region":"440800"},
{"name":"茂名市","region":"440900"},
{"name":"肇庆市","region":"441200"},
{"name":"揭阳市","region":"445200"},
{"name":"清远市","region":"441800"},
{"name":"潮州市","region":"445100"},
{"name":"云浮市","region":"445300"}
 ]

//卡片监听
$(document).on('click', '.bizcard-item', function(e) {
	if (e.target.nodeName === "DIV") {
		var ele = e.target || e.srcElement; //兼容ie9或以下版本自定义属性
		var url = "";
		if (ele.className === "bizcard-title" || ele.className === "bizcard-desc" || ele.className === "bizcard-info") {
			if("IE" === myBrowser()){
				url = this.attributes["1"].nodeValue
			}else{
				url = this.dataset.href;
			}
		}else{
			url = ele.getAttribute("data-href");
		}
		location.href = url;
	}
	if (e.target.nodeName === "svg" || e.target.nodeName === "use") {
		var ele = e.currentTarget || e.srcElement;
		location.href = ele.getAttribute("data-href");
	}
})

/**
 * 获取城市信息
 * @param codeStr
 * @param lv2name
 * @param mattersType  个人服务或法人服务
 * @param mattersTypeClassify  
 */

function getCity(id, region, lv1_name,lv1_code,lv2_name,matter_type){	
	$(".modal-citylocation a").html("");
	$("#citylist").html("");
	$.ajax({
		type : "POST",
		url : ctx + "/custom-config/gdbsBusiness/getCodeDetail",
		data : {
			type: matter_type,
			id: id,
			region: region
		},
		dataType : "json",
		success : function(result) {
			if((result.statusCode=="200" || result.statusCode==200) && result.data 
					&& result.data.data){							
				
				var codeArr = result.data.data[0].code;
				var codes = []
				var isProLevel = false;
				//判断广东省是否有事项数据,事项编码数组
				$.each(codeArr,function(i,code1){
					$.each(code1.code,function(k,code2){
						if(codes.length < 200){
							codes.push(code2);
						}
					})
					if(code1.region === "440000" && code1.code.length > 0){
						isProLevel = true;
					}
				})
				
				var curr_areaCode = "";
				getIpLocation(function(data){
					if(!data || (data && data.areaCode=="440000")) {
						$(".modal-citylocation a").html("暂时无法定位");
					} else {
						$(".modal-citylocation a").html(data.areaName);
						curr_areaCode = data.areaCode;
					}
				});
				var html = [];
				var flag = false;
				$(".modal-citylocation a").attr("class","modal-citylist-disabled");
				$.each(cityList,function(i,city){
					flag = false;
					var lvUrl = ctx + '/lv3/hot?region='+region+'&type='+matter_type+'&id='+id+'&area_code='+city.region+'&lv1_code='+lv1_code+'&lv1_name='+encodeURIComponent(lv1_name)+'&lv2_name='+encodeURIComponent(lv2_name);
					
					$.each(codeArr,function(i,codeObj){
						if(city.region === codeObj.region){							
							html.push('<a href="'+lvUrl+'" class="modal-citylist-item" >'+codeObj.city+'</a>');
							flag = true;
							//定位城市设置
							if(curr_areaCode.substring(0,4) === codeObj.region.substring(0,4)){
								$(".modal-citylocation a").attr("href",lvUrl);
								$(".modal-citylocation a").removeAttr("class");
							}
							return false;
						}
					});
					if(!flag){
						html.push('<a href="javascript:void(0);" class="modal-citylist-item modal-citylist-disabled">'+city.name+'</a>');					
					}
				})
				$("#citylist").html(html.join(""));				
			}
		}
	});
}

function urlBindCity(urlObj){
	var cla = "modal-citylist-item";
	var url = "";
	var html = [];
	
	$(".modal-citylocation a").attr("class","modal-citylist-disabled");
	var curr_areaCode = "";
	getIpLocation(function(data){
		if(!data || (data && data.areaCode=="440000")) {
			$(".modal-citylocation a").text("暂时无法定位");
		} else {
			$(".modal-citylocation a").text(data.areaName);
			curr_areaCode = data.areaCode;
		}
	});
	
	$("#citylist").empty();
	$.each(cityList,function(i,city){
		$.each(urlObj,function(j,obj){
			if(obj){
				if(city.name === obj.city){
					if(obj.url){
						url = obj.url;
					}
					
					$(".modal-citylocation a").attr("href", url);
					$(".modal-citylocation a").removeAttr("class");
					return false;
				}
			}
		})
		if(!url){
			cla += " modal-citylist-disabled";
		}
		html.push('<a href="'+url+'" class="'+cla+'">'+city.name+'</a>');
		url = "";
		cla = "modal-citylist-item";
	});
	
	$("#citylist").html(html.join(""));
}


